#include "stdafx.h"
#include "../aclib/HexParser.h"

namespace AC = AppliedCryptography;
using ::testing::Return;

TEST(AESEncrypt, 128bitKey)
{
	AC::AES::Encryptor<AC::AES::key128bit> aes;
	AC::AES::Key<AC::AES::key128bit> key;
	AC::AES::Plaintext plain;
	AC::AES::Chypertext chyper;
	AC::HexParser hx;
	std::string exception_what;

	ASSERT_NO_THROW({
		key.Set(hx("00010203050607080A0B0C0D0F101112"));
	});

	ASSERT_NO_THROW({
		plain.Set(hx("506812A45F08C889B97F5980038B8359"));
	});

	ASSERT_NO_THROW({
		aes.SetKey(key);
	});

	ASSERT_NO_THROW({
		aes.Process(plain, chyper);
	});

	EXPECT_TRUE(hx("D8F532538289EF7D06B506A4FD5BE9C9") == chyper.Get()) << "  chyper: " << hx(chyper.Get());
};

TEST(AESEncrypt, 192bitKey)
{
	AC::AES::Encryptor<AC::AES::key192bit> aes;
	AC::AES::Key<AC::AES::key192bit> key;
	AC::AES::Plaintext plain;
	AC::AES::Chypertext chyper;
	AC::HexParser hx;
	std::string exception_what;

	ASSERT_NO_THROW({
		key.Set(hx("95A8EE8E89979B9EFDCBC6EB9797528D432DC26061553818"));
	});

	ASSERT_NO_THROW({
		plain.Set(hx("4EC137A426DABF8AA0BEB8BC0C2B89D6"));
	});

	ASSERT_NO_THROW({
		aes.SetKey(key);
	});

	ASSERT_NO_THROW({
		aes.Process(plain, chyper);
	});

	EXPECT_TRUE(hx("B18BB3E7E10732BE1358443A504DBB49") == chyper.Get()) << "  chyper: " << hx(chyper.Get());
};

TEST(AESEncrypt, 256bitKey)
{
	AC::AES::Encryptor<AC::AES::key256bit> aes;
	AC::AES::Key<AC::AES::key256bit> key;
	AC::AES::Plaintext plain;
	AC::AES::Chypertext chyper;
	AC::HexParser hx;
	std::string exception_what;

	ASSERT_NO_THROW({
		key.Set(hx("95A8EE8E89979B9EFDCBC6EB9797528D432DC26061553818EA635EC5D5A7727E"));
	});

	ASSERT_NO_THROW({
		plain.Set(hx("4EC137A426DABF8AA0BEB8BC0C2B89D6"));
	});

	ASSERT_NO_THROW({
		aes.SetKey(key);
	});

	ASSERT_NO_THROW({
		aes.Process(plain, chyper);
	});

	EXPECT_TRUE(hx("2F9CFDDBFFCDE6B9F37EF8E40D512CF4") == chyper.Get()) << "  chyper: " << hx(chyper.Get());
};

